// phalanx sinc.hpp.cu header file

// Copyright (c) 2011 - 2011 Kohei Takahashi (Flast).
// Distributed under the MIT license. for more detail see COPYING.

// Function name with _fm suffix is forced using Fast-Math version.

#ifndef IG_PHALANX_MATH_FUNCTIONS_SINC_HPP_CU_ONCE_
#define IG_PHALANX_MATH_FUNCTIONS_SINC_HPP_CU_ONCE_

#include <phalanx/config.hpp.cu>

#include <cfloat>

#include <phalanx/detail/define_func.hpp.cu>

#include <phalanx/math/detail/operators.hpp.cu>
#include <phalanx/math/constant.hpp.cu>
#include <phalanx/math/functions/math_functions.hpp.cu>

namespace phalanx
{

namespace math
{

LO_PHALANX_PP_DEF_OVERLOAD( true )(
  sinc_denorm,
  ( 2, 1 ),
  ( float, double ),
  ( ( float ), ( double ) ),
  ( x_ ),
  {
      if ( math_detail::_leq( abs( x_ ), epsilon_() ) )
      { return one_(); }
      return sin( x_ ) / x_;
  } );
  //if ( abs( x_ ) <= epsilon_() )

LO_PHALANX_PP_DEF_OVERLOAD( true )(
  sinc,
  ( 2, 1 ),
  ( float, double ),
  ( ( float ), ( double ) ),
  ( x_ ),
  { return sinc_denorm( math_detail::_mul( x_, pi_() ) ); } );
  //{ return sinc_denorm( x_ * pi_() ); } );

LO_PHALANX_PP_DEF_OVERLOAD( false )(
  sinc_denorm_fm,
  ( 2, 1 ),
  ( float, double ),
  ( ( float ), ( double ) ),
  ( x_ ),
  {
      if ( math_detail::_leq( abs( x_ ), epsilon_() ) )
      { return one_(); }
      return sin_fm( x_ ) / x_;
  } );
  //if ( abs( x_ ) <= epsilon_() )

LO_PHALANX_PP_DEF_OVERLOAD( false )(
  sinc_fm,
  ( 2, 1 ),
  ( float, double ),
  ( ( float ), ( double ) ),
  ( x_ ),
  { return sinc_denorm( math_detail::_mul( x_, pi_() ) ); } );
  //{ return sinc_denorm( x_ * pi_() ); } );

} // namespace math

} // namespace phalanx

#endif // IG_PHALANX_MATH_FUNCTIONS_SINC_HPP_CU_ONCE_

